//
//  DoctorInfoViewController.m
//  hospitalVIP
//
//  Created by Xiaoyan on 13-1-2.
//  Copyright (c) 2013年 MEETStudio. All rights reserved.
//

#import "DoctorInfoViewController.h"

static ASIHTTPConnection *doctors_connect;

@interface DoctorInfoViewController ()

@end

@implementation DoctorInfoViewController

@synthesize doctorInfoDict;


- (void)dealloc{
    
    [doctorInfoDict release];
    
    [iconImageView release];
    [doctorName release];
    [birthDay release];
    [sex release];
    
    [myScrollView release];
    
    //

    [PosLevel_Name release];
    [PosLevel_Desc release];
    [Doctor_Desc release];
    //

    [phone1 release];
    [phone2 release];
    
    //
    [post_Code release];
    [work_unit release];
    [home_address release];
    //

    [email release];
    
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (id)initWithDoctorId:(NSString *)doctorId{
    
    self = [super init];
    if (self) {
        self._doctorID = doctorId;
    }
    
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [myScrollView setContentSize:CGSizeMake(320, 700)];
    
    [self loadDoctorInfo];
    
}


- (void)loadDoctorInfo{
    
    NSString *urlString = [NSString stringWithFormat:@"%@/doctor?Doctor_ID=%@",UCENTERBASEURL,self._doctorID];
	NSURL *url = [NSURL URLWithString:urlString];
    
    if (doctors_connect != nil) {
        doctors_connect.connectionDelegate = nil;
        [doctors_connect release];
        doctors_connect = nil;
    }
    
    doctors_connect = [[ASIHTTPConnection alloc] initGETWithURL:url resultDict:YES isCache:YES];
    doctors_connect.connectionDelegate = self;
    
    [doctors_connect startAsynchronous];
    
    [LoadingView showDefaultLoadingView];
}


- (void)requestFinished:(ASIHTTPConnection *)connection resultDict:(NSDictionary *)dict URL:(NSURL *)url info:(NSDictionary *)info{
    [LoadingView hideWithAnimated:YES];
    
    self.doctorInfoDict = [dict objectForKey:@"doctormap"];
    
    [self initDoctorInfo];
    
}

- (void)requestFailed:(ASIHTTPConnection *)connection error:(NSError *)error URL:(NSURL *)url info:(NSDictionary *)info{
    
     [LoadingView hideWithAnimated:YES];
}


- (void)initDoctorInfo{
    
    doctorName.text = [doctorInfoDict objectForKey:@"doctor_Name"];
    birthDay.text = [doctorInfoDict objectForKey:@"birthday"];
    sex.text = [doctorInfoDict objectForKey:@"doctor_Sex"];
    
    PosLevel_Name.text = [doctorInfoDict objectForKey:@"posLevel_Name"];
    PosLevel_Desc.text = [doctorInfoDict objectForKey:@"posLevel_Desc"];
    Doctor_Desc.text = [doctorInfoDict objectForKey:@"doctor_Desc"];
    
    phone1.text = [doctorInfoDict objectForKey:@"phone1"];
    phone2.text = [doctorInfoDict objectForKey:@"phone2"];
    
    post_Code.text = [doctorInfoDict objectForKey:@"post_Code"];
    work_unit.text = [doctorInfoDict objectForKey:@"posLevel_Name"];
    home_address.text = [doctorInfoDict objectForKey:@"home_Addr"];
    
    email.text = [doctorInfoDict objectForKey:@"email_Addr"];
    
    
    
}




- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
